package cate.common.table.fight.buff.row;

import cate.common.table.ERow;
import cate.common.table.XSSFRowWrap;
import cp.solution.util.str.Str;
import cate.common.util.XT;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

@NoteClass("buff基础")
@Data
public class BuffRow extends ERow {

    @NoteField("原型ID")
    public int protoId;

    @NoteField("等级")
    public int level;

    @NoteField("启用等级覆盖")
    public boolean levelOverride;

    @NoteField("名称")
    public String name;

    @NoteField("标签")
    private String tagStr;

    @NoteField("效果类型")
    public String effectType;

    @NoteField("效果配置")
    public String effectArgsCode;

    @NoteField("属性改变")
    public String attrCode;

    @NoteField("持续回合数")
    public int lastRound;

    @NoteField("是否可被驱散")
    public boolean dispel;

    @NoteField("死亡是否消除")
    public boolean deadInvalid;

    @NoteField("死亡也可添加")
    public boolean deadAddable;

    @NoteField("最大叠加数量")
    public int pileMax;

    @NoteField("是否有利")
    public boolean good;

    @NoteField("是否通知前端")
    public boolean notice;

    @Override
    public void parse(XSSFRowWrap xrw) {
        super.parse(xrw);
        this.id = xrw.getInteger("BuffID",0);
        this.protoId = xrw.getInteger("原型ID", this.id);
        this.level = xrw.getInteger("等级", 0);
        this.levelOverride = xrw.getBoolean("启用等级覆盖",false);
        this.name = xrw.getString("名称");
        this.tagStr = xrw.getString("标签");
        this.effectType = xrw.getString("效果类型");
        this.effectArgsCode = xrw.getString("效果配置");
        this.attrCode = xrw.getString("属性改变");
        this.lastRound = xrw.getInteger("持续回合数",-1);


        this.dispel = xrw.getBoolean("是否可被驱散", false);
        this.deadInvalid = xrw.getBoolean("死亡是否消除",true);
        this.deadAddable = xrw.getBoolean("死亡也可添加", false);
        this.pileMax = xrw.getInteger("最大叠加数量",1);
        this.good = xrw.getBoolean("是否有利",false);

        this.notice = xrw.getBoolean("是否通知前端",false);
    }

    private List<String> tags;

    @Override
    public void decode() {
        tags = Str.str2StrList(tagStr, "#");
    }

    public boolean containTag(String tag) {
        if (XT.isBlank(tags) || StringUtils.isBlank(tag)) {
            return false;
        }
        for (String s : tags) {
            if (StringUtils.equals(s, tag)) {
                return true;
            }
        }
        return false;
    }

    public boolean containTags(List<String> tags) {
        if (XT.isBlank(this.tags) || XT.isBlank(tags)) {
            return false;
        }
        for (String s : this.tags) {
            if (tags.contains(s)) {
                return true;
            }
        }
        return false;
    }

}
